<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    // 父类
    class Person {

        constructor(name, age, sex) {
            this.name = name
            this.age = age
            this.sex = sex
        }

        say() {
            console.log(`我是${this.name}`);
        }

        static type = "人"

        static eat() {
            console.log(`每天要吃早饭`);
        }
    }
    /* 
        class Student extends Person {
    
                constructor(){
                    //Must call super constructor in derived class before accessing 'this' or returning from derived constructor
                    // 【在使用this之前】，你必须调用父类的constructor方法：super()  
                    // super() 方法就代表父类的constructor
                    super()
    
    
                }
        }
    
        let s=new Student("小明",17,"男")
        console.log(s);
        //{name: undefined, age: undefined, sex: undefined} 虽然不报错误了，但是传值不对
        // 因为子类有了自己的constructor,那么传值传给的是自己的constructor
     */




    class Student extends Person {

        constructor(n,a,s) {// n a s 是形参
            console.log(n,a,s);//小明 17 男 

            // 父类的constructor 和 子类constructor里头的super 就相当于一个函数封装一个函数调用
            super(n,a,s)// n a s 对于super来说是实参

        }
    }

    // 此时new Student("小明", 17, "男") 传的参数，是传给了子类的constructor
    let s = new Student("小明", 17, "男")
    console.log(s);//Student {name: '小明', age: 17, sex: '男'}












</script>